<template>
  <entity-view
    form-item-width="33.33%"
    @submit="submit"
    ref="form"
    :model="beanInfo"
    :rules="rules"
  >
    <div class="sub-content-flex">
      <form-item
        label="业务控制规则"
        v-model="beanInfo.bizCtrlRule"
        prop="bizCtrlRule"
        inputType="select"
        :options="bizCtrlRuleList"
        @change="(value) => handleChange(value, 'bizCtrlRule')"
      ></form-item>
      <form-item
        label="营业开始时间"
        prop="bizStartTime">
        <a-time-picker v-model="beanInfo.bizStartTime" format="HHmmss" @change="(value) => dateChange(value, 'bizStartTime')" />
      </form-item>
      <form-item
        label="营业截止时间"
        prop="bizEndTime">
        <a-time-picker v-model="beanInfo.bizEndTime" format="HHmmss"	@change="(value) => dateChange(value, 'bizEndTime')"  />
      </form-item>
      <form-item
        label="通道超时时间(毫秒)"
        v-model="beanInfo.channelTimeout"
        prop="channelTimeout"
      >
      </form-item>
    </div>
    <div class="btn-wrapper">
      <a-button type="primary" html-type="submit" @click="goUpdateOne(preOne)"
        >上一步</a-button
      >
      <a-button type="primary" html-type="submit" @click="goUpdateOne(nextOne)"
        >下一步</a-button
      >
      <a-button @click="close">取消</a-button>
    </div>
  </entity-view>
</template>

<script>
import EntityView from "../../../../components/common/entityView/EntityView";
import FormItem from "../../../../components/common/entityView/FormItem";
import moment from "moment";
moment.locale('zh-cn');

export default {
  name: "TimeInfoForm",
  components: { EntityView, FormItem },
  inject: ["PDstChannelContext", "operationContext"],
  data: function () {
    return {
      pageInfo: {
        mchntType: "",
      },
      beanInfo: {},
      bizCtrlRuleList: [
        { value: "0", name: "按自然日" },
        { value: "1", name: "按工作日" },
      ],
      rules: {
        bizCtrlRule: [{ required: true, message: "必填", trigger: "blur" }],
        bizStartTime: [{ required: true, message: "必填", trigger: "blur" }],
        bizEndTime: [{ required: true, message: "必填", trigger: "blur" }],
        channelTimeout: [{ required: true, message: "必填", trigger: "blur" }],
      },
      startTime:'',
      endTime:'',
      operatorType: "",
      preOne:'baseInfo',
      nextOne:'limitInfo',
    };
  },
  methods: {
    async getPageInfo() {
      try {
        const res = await this.$get("/admin/igas/pDstChannelInfo/editTime", {
          dstChannelId: this.PDstChannelContext.beanInfo.dstChannelId,
          instId: this.PDstChannelContext.beanInfo.instId,
          optFlag: "upd",
        });
        this.beanInfo = res.data.entity || {};
        this.startTime= this.beanInfo.bizStartTime
        this.endTime= this.beanInfo.bizEndTime
        if (this.beanInfo.bizStartTime=='*'){
          this.beanInfo.bizStartTime='000000'
        }
        if (this.beanInfo.bizEndTime=='*'){
          this.beanInfo.bizEndTime='000000'
        }
        this.beanInfo.bizStartTime= moment('20000101T'+this.beanInfo.bizStartTime);
        // this.$set(this.beanInfo, 'bizStartTime', moment('12:08:23', 'HH:mm:ss'))
        this.beanInfo.bizEndTime= moment('20000101T'+this.beanInfo.bizEndTime);

      } catch (e) {
        console.error(e);
      }
    },
    close(){
      this.PDstChannelContext.modalVisible=false;
    },
    handleChange(value, param) {
      this.beanInfo[param] = value;
    },
     dateChange(value,param){
       this.beanInfo[param] = value ;
       //this.beanInfo[param] = moment(value._i).format('HHMMSS');
    },
    submit() {
      this.$emit("submit", ...arguments);
    },
    resetFields() {
      return this.$refs.form.resetFields();
    },
    async goUpdateOne(param) {
      if (this.operationContext.operatorType=='view'){
        const res = await this.$refs.form.validate();
        this.operationContext.tabActiveKey = param
      }else {
      const res = await this.$refs.form.validate();
      if (res) {
        this.operationContext.tabActiveKey = param;
        this.beanInfo.bizStartTime=this.beanInfo.bizStartTime.format('HHmmss');
        this.beanInfo.bizEndTime=this.beanInfo.bizEndTime.format('HHmmss');

        const params = {};
        Object.assign(params, this.beanInfo, {
          id: this.beanInfo.id,
          optFlag: "upd",
        });
        const res = await this.$put(
          "/admin/igas/pDstChannelInfo/update",
          params
        );
        if (res.status === 200) {
          this.$message.success("保存成功！");
          return true;
        } else {
          this.$message.error(res.data.message);
          return false;
        }
      }
      }
    },
  },
  async mounted() {
    this.operatorType = this.operationContext.operatorType;
  },
};
</script>

<style scoped>
.btn-wrapper {
  padding: 0 10px;
  width: 100%;
  text-align: center;
}
.subtitle {
  width: 100%;
  font-size: 16px;
  margin-bottom: 10px;
  padding: 0 10px;
}

.sub-content-flex {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.sub-content-block {
  display: block;
  flex-wrap: wrap;
  width: 100%;
  padding: 0 10px;
}
.checkAll {
  display: block;
  line-height: unset;
}
</style>
